package com.mz.mattress.client.task;

import com.mz.mattress.api.common.StepBean;
import lombok.Data;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

@Data
public class TaskStepBean implements Serializable {

    private static final long serialVersionUID = 1L;

    private List<StepBean> stepList;

    private volatile boolean finishFlag;
    private String tokenId;
    private int totalStep = 0;
    private int currStep = 0;
    private boolean successFlag;

    public void nextStep() {
        ++currStep;
    }

    public StepBean queryCurrStep() {
        return stepList.get(currStep);
    }

    public boolean canFinish() {
        return finishFlag || currStep >= totalStep;
    }

    public void setStepList(List<StepBean> stepList) {

        if (stepList == null) {
            return;
        }

        Collections.sort(stepList);

        this.stepList = stepList;
        this.totalStep = stepList.size();
    }

}
